package com.pyrsana.faith.retreat

class RetreatTagLib {
    
    static namespace = "retreat"
    
    /**
     * Renders given {@link Location}.
     *
     * @attr location REQUIRED The {@link Location} to display.
     * @attr br Whether to split location into multiple lines. Default 'false'.
     */
    def location = { attrs ->
        Location location = attrs.location
        String br = attrs.br == 'true' ? '<br />' : '&nbsp;&nbsp;'
		
        String name =  location.url ? '<a target="_blank" href="' + location.url + '">' + location.name + '</a>' : location.name
        out << name + br + "(" + location.streetAddress + ", " + location.city + ", " + location.state + " " + location.zipcode + ")"
    }
    
    /**
     * @attr passage REQUIRED The {@link Passage} to display.
     * @attr displayTranslation Whether to display the translation. Default 'true'
     */
    def passage = { attrs ->
        boolean displayTranslation = attrs.displayTranslation ? Boolean.valueOf(attrs.displayTranslation.toString()) : true
        out << render(template:'/templates/com/pyrsana/faith/retreat/passage', model:[passage:attrs.passage, displayTranslation:displayTranslation])
    }
    
    /**
    * Renders given {@link TransportationLeg}s
    *
    * @attr legs REQUIRED The collection of {@link TransportationLeg}s to display
    * @attr displayNotes Whether to output notes. Default 'false'.
    */
   def transportationLegs = { attrs ->
       attrs.legs.each { leg ->
           boolean displayNotes = attrs.displayNotes ? Boolean.valueOf(attrs.displayNotes.toString()) : false
           out << render(template:'/templates/com/pyrsana/faith/retreat/transportationLeg', model:[leg:leg, displayNotes:displayNotes])
       }
   }
   
   /**
   * Renders given {@link TransportationLeg}
   *
   *@
   * @attr leg REQUIRED The {@link TransportationLeg} the request is for.
   * @attr requested REQUIRED Whether transportation has been requested.
   */
   def transportationRequest = { attrs ->
       out << render(template:'/templates/com/pyrsana/faith/retreat/transportationLeg', model:[leg:attrs.leg, displayNotes:true, form:true, checked:attrs.requested])
   }

   /**
    * Renders given workshops and their requests as a lined table.
    * 
    * @attr requests REQUIRED The {@link WorkshopRequest}s to match with given workshops.
    * @attr workshops REQUIRED The {@link Workshop}s to match with given requests.
    */
   def workshopRequests = { attrs ->
       List<Workshop> workshops = attrs.workshops.sort{a, b -> a.title.compareTo(b.title)}
       out << render(template:'/templates/com/pyrsana/faith/retreat/workshopRequests', model:[requests:attrs.requests, workshops:workshops])
   }
}
